package com.example.grpc.server.service;

import io.grpc.stub.StreamObserver;
import net.devh.boot.grpc.server.service.GrpcService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import proto.com.example.grpc.common.UserProto;
import proto.com.example.grpc.common.UserServiceGrpc;

/**
 * @author linht
 * @date 2025/9/10 16:50
 */
@GrpcService
public class UserGrpcService extends UserServiceGrpc.UserServiceImplBase {

    private static final Logger logger = LoggerFactory.getLogger(UserGrpcService.class);


    @Override
    public void getUser(UserProto.UserRequest request, StreamObserver<UserProto.UserResponse> responseObserver) {
        logger.info("获取用户信息: {}", request.getUserId());

        UserProto.UserResponse response = UserProto.UserResponse.newBuilder()
                .setUserId(request.getUserId())
                .setUsername("user" + request.getUserId())
                .setEmail("user" + request.getUserId() + "@example.com")
                .setCreatedAt(System.currentTimeMillis())
                .build();

        responseObserver.onNext(response);
        responseObserver.onCompleted();
    }
}
